package com.zhang.crm.result;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一返回对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class R {
    private int code;

    private String msg;

    private Object data;

    public static R OK(CodeEnum codeEnum, Object o) {
        return R.builder().code(codeEnum.getCode()).msg(codeEnum.getMsg()).data(o).build();
    }
    public static R OK() {
        return R.builder().code(200).msg("成功").build();
    }
    public static R OK(Object o) {
        return R.builder().code(CodeEnum.LOGIN_SUCCESS.getCode()).msg(CodeEnum.OPERATE_SUCCESS.getMsg()).data(o).build();
    }

    public static R FAIL(CodeEnum codeEnum) {
        return R.builder().code(codeEnum.getCode()).msg(codeEnum.getMsg()).build();
    }
    public static R FAIL(CodeEnum codeEnum, String msg) {
        return R.builder().code(codeEnum.getCode()).msg(codeEnum.getMsg()).data(msg).build();
    }
    public static R FAIL(String msg) {
        return R.builder().code(600).msg(msg).build();
    }

}
